#include "kmlWriter.h"

KMLWriter::KMLWriter(vector<Place>& places):
	places_(places) { }	

KMLWriter::~KMLWriter() { }

void KMLWriter::Save(string path){

    ofstream fout;
    fout.open(path.c_str());   

	fout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
	fout << "<kml>\n";
	fout << "<Document>\n";

	for(std::vector<Place>::iterator i = places_.begin(); i != places_.end(); ++i){
		fout << "\t<Placemark>\n";
		fout << "\t\t<address>\n";
		fout << "\t\t\t" << (*i).getAddress() << "\n";
		fout << "\t\t</address>\n";
		fout << "\t\t<name>" << (*i).getName() << "</name>\n";

		fout << "\t\t<description>\n";
		fout << "\t\t<![CDATA[\n";
		fout << "\t\t\t" << (*i).getAddress() << "\n";
		fout << "\t\t\t" << (*i).getRank() << "\n";
		fout << "\t\t]]>\n";
		fout << "\t\t</description>\n";
 	
		fout << "\t\t<Point>\n";
		fout << "\t\t\t<coordinates>" << (*i).getLon() << "," << (*i).getLat() << "</coordinates>\n";
		fout << "\t\t</Point>\n";
		
		fout << "\t</Placemark>\n";	
	}

	fout << "</Document>\n";
	fout << "</kml>\n";
	
    fout.close();
}






